﻿Imports ASAP.InterfazNegocio

Public Class frmAnalisiRonda

    Private nivel As String
    Private ronda As Integer

    Private Sub frmAnalisiRonda_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        cbNivel.SelectedItem = cbNivel.Items(1)
        cbRonda.SelectedItem = cbRonda.Items(0)
    End Sub

    Private hash As Generic.Dictionary(Of String, List(Of Agente.EjerRevisionRonda))

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click

        nivel = CStr(CType(cbNivel.SelectedItem, ComboBoxItem).Content)
        ronda = CInt(CType(cbRonda.SelectedItem, ComboBoxItem).Content)

        hash = Agente.AnalisisRonda(nivel, ronda)
        Me.listTeorias.ItemsSource = hash.Keys

    End Sub

    Private Sub listTeorias_SelectionChanged(sender As Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles listTeorias.SelectionChanged

        Me.gridResultados.ItemsSource = hash(CStr(Me.listTeorias.SelectedValue))

    End Sub

    Private Sub VerLeccion_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles VerLeccion.Click

        Dim ejerRonda As ASAP.InterfazNegocio.Agente.EjerRevisionRonda
        ejerRonda = CType(gridResultados.SelectedItem, Agente.EjerRevisionRonda)

        Dim ejer As New TiposDatosSTE.Ejercicio
        ejer.Volumen = ejerRonda.Volumen
        ejer.Tema = ejerRonda.Tema
        ejer.TipoEjercicio = ejerRonda.TipoEjer
        ejer.Nivel = nivel

        ejer.Ingles = ejerRonda.Ingles
        ejer.Castellano = ejerRonda.Castellano


        AbrirImagenesLibro(ejer)
    End Sub

    Private Sub AbrirImagenesLibro(ejer As TiposDatosSTE.Ejercicio)

        Dim PathImagenes As String = My.Application.Info.DirectoryPath & "\tmp"

        If Not IO.Directory.Exists(PathImagenes) Then
            IO.Directory.CreateDirectory(PathImagenes)
        End If

        Dim PathImagen As String = PathImagenes & "\libro.tif"

        My.Computer.FileSystem.WriteAllBytes(PathImagen, Agente.DameImagenesLibro(ejer), False)
        System.Diagnostics.Process.Start(PathImagen)
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click

        Dim str As String = ""

        If hash IsNot Nothing Then

            For Each k As String In hash.Keys
                str = str & k
                str = str & " => " & hash.Item(k).Count & vbCrLf
            Next

        End If

        MsgBox(str)

    End Sub
End Class
